package boogui.movie;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

import boogui.member.UserVO;

public class MovieDisplay {
	
	private static UserVO u;
	private BtnActionListener bal = null;

	private static MovieSelectService mselect = null;
	private static MovieVO m = null;
	private static MovieService ms = null;
	
	private JTable movname;
	private JLabel posterlbl;

	private JTable movarea;
	private JTable movcinema;

//	private JTable movtheater;
	private JPanel movresv;

	protected DefaultTableModel model2;

	private static JScrollPane sPmovarea;
	private static JScrollPane sPmovcinema;
	private JPanel movpanel;
	private JLabel isPlaylbl;

	private static JPanel movieinfopanel;

	private JLabel movieinfo1;
	private JTable movpeople;
	private JTable movtime;

	private static String movinfo;
	private static String synop;
	private JTextArea movsynop1;
	private JPanel panel;
	private JLabel lblNewLabel;
	private JPanel panel_1;
	private JLabel label_1;
	private static String isplay;
	private JPanel caldpanel;
	private JPanel calhdr;
	private JScrollPane calsp;
	private JButton button;
	private JButton button_1;
	private JLabel caldate;
	private JTable caltbl;
	private Calendar ca;
	private JScrollPane sPmovdate;
	private static JScrollPane sPmovpeople;
	private JComboBox<String> peopleCbx;
	private static JScrollPane sPmovtime;
	private JComboBox<String> timeCbx;
	private JScrollPane sPmovname;
	private JPanel peopanel;
	private JComboBox<String> rateCbx;
//	private JLabel mainImg;
	private JLabel mainImg1;
	private JScrollPane sPsynop;

	private DefaultTableCellRenderer cell;

	// 처음 화면
	public MovieDisplay(JPanel contentPane, UserVO u) {		
		bal = new BtnActionListener(u);
		lblNewLabel = new JLabel();
		panel = new JPanel();
		movsynop1 = new JTextArea();
		mselect = new MovieSelectService();
		m = new MovieVO();
		ms = new MovieService();
		peopanel = new JPanel();
		sPsynop = new JScrollPane();
		sPmovpeople = new JScrollPane();
		sPmovtime = new JScrollPane(); 
		sPmovdate = new JScrollPane();
		
		sPmovarea = new JScrollPane(); // 스크롤페인 지역
		sPmovcinema = new JScrollPane(); // 스크롤 페인 영화관
		mselect = new MovieSelectService();
		m = new MovieVO();
		movieinfo1 = new JLabel();
		movieinfopanel = new JPanel();
		movsynop1 = new JTextArea();
		caldpanel = new JPanel();
		calhdr = new JPanel();
		caltbl = new JTable();
		ca = Calendar.getInstance();
		String currentdate = ca.get(Calendar.YEAR) + "년" + (ca.get(Calendar.MONTH) + 1) + "월";
		caldate = new JLabel(currentdate);
		calsp = new JScrollPane();

		movresv = new JPanel();
		movresv.setBorder(new EmptyBorder(1, 10, 10, 10));
		FlowLayout fl_movresv = (FlowLayout) movresv.getLayout();
		fl_movresv.setAlignment(FlowLayout.LEFT);
		movresv.setPreferredSize(new Dimension(10, 300));
		contentPane.add(movresv, BorderLayout.SOUTH);

		movpanel = new JPanel();

		movpanel.setBorder(new EmptyBorder(30, 10, 10, 10));
		movpanel.setPreferredSize(new Dimension(10, 400));
		contentPane.add(movpanel, BorderLayout.NORTH);
		movpanel.setLayout(new BorderLayout(0, 0));

		mainImg1 = new JLabel();		
		mainImg1.setIcon(new ImageIcon(getClass().getResource("/images/mainlogo.jpg")));
		movpanel.add(mainImg1, BorderLayout.WEST);
		mainImg1.setPreferredSize(new Dimension(988, 300));

		
		posterlbl = new JLabel();		

		posterlbl.setHorizontalAlignment(SwingConstants.CENTER);
		posterlbl.setPreferredSize(new Dimension(230, 300));

		movpanel.add(movieinfopanel, BorderLayout.CENTER);
		movieinfopanel.setLayout(new BorderLayout(0, 0));
		

		movietitle();
	}

	// 제목
	public void movietitle() {

		sPmovname = new JScrollPane(); // 스크롤페인 영화이름

		sPmovname.setFont(new Font("굴림", Font.PLAIN, 18));
		sPmovname.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sPmovname.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		sPmovname.setPreferredSize(new Dimension(195, 250));
		movresv.add(sPmovname);

		DefaultTableModel model = new DefaultTableModel() {
			@Override
			public boolean isCellEditable(int row, int column) {
				return false;// 열수정 불가 } };
			}
		};
		String title[] = { "<html><font size='5' face='맑은 고딕'><b>상영중인 영화</b></font></html>" };
		model.setColumnIdentifiers(title);

		for (MovieVO m : mselect.clickMovie()) {
			model.addRow(new String[] { m.getMovtitle() });
		}

		movname = new JTable(model);
		// movname.setBackground(Color.WHITE);		
		movname.setRowHeight(30);		
		
		movname.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 1) {					
					movpanel.remove(mainImg1);
					//movieinfopanel.remove(mainImg);
					JTable table = (JTable) e.getSource();
					table.validate();
					//table.repaint();
					int row = table.getSelectedRow(); // 선택행
					int col = table.getSelectedColumn();// 선택열

					String val = (String) table.getValueAt(row, col);
					m.setMovtitle(val);
					movpanel.add(posterlbl, BorderLayout.WEST);
					ms.readPosterImage(m.getMovtitle(), posterlbl, 210, 300);
					moviearea(mselect.clickArea(m));
					movieinfo(m);
					movsynop(m);
					movisplay(m);					
					movname.validate();
			
					movname.setVisible(true);
				}
			}
		});
		sPmovname.setViewportView(movname);
		moviearea(new ArrayList<MovieVO>());
	}

	// 영화 정보 
	private void movieinfo(MovieVO m) {

		ms.searchmovie(m);
		// System.out.println(m.getMovactor1());
	
		movinfo = "<html><font face='맑은 고딕'><b>감 독</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + m.getMovdirector()
				+ "<br/><br/><b>출 연</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + m.getMovactor1()
				+ "&nbsp;<font color='#aaaaaa'>,</font>&nbsp;" + m.getMovactor2() + "&nbsp;<font color='#aaaaaa'>,</font>&nbsp;" + m.getMovactor3()
				+ "<br/><br/><b>등 급</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + m.getMovrating()
				+ "<br/><br/><b>개봉일</b>&nbsp;&nbsp;&nbsp;&nbsp;" + m.getMovplaydate().substring(0, 10)
				+ "<br/><br/><b>장 르</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + m.getMovgenre1()
				+ "&nbsp;<font color='#aaaaaa'>,</font>&nbsp;" + m.getMovgenre2() + "<br/><br/><b>상영시간</b>&nbsp;&nbsp;" + m.getMovruntime()
				+ "분<font></html>";
		// JScrollPane sPmovname = new JScrollPane(); // 스크롤페인 영화이름
		movieinfopanel.remove(movieinfo1);
		movieinfo1 = new JLabel(movinfo);
		movieinfo1.setBorder(new EmptyBorder(10, 30, 0, 0));
		movieinfo1.setVerticalAlignment(SwingConstants.TOP);
		movieinfo1.setPreferredSize(new Dimension(375, 260));
		movieinfo1.setHorizontalAlignment(SwingConstants.LEFT);
		movieinfo1.setFont(new Font("굴림", Font.PLAIN, 15));
		movieinfopanel.add(movieinfo1, BorderLayout.WEST);

	}

	// 상영 여부
	private void movisplay(MovieVO m) {
		m.setMovisplay("");
		ms.searchmovie(m);
		switch (m.getMovisplay()) {
		case "N":
			isplay = " 상영 예정 작";
			break;
		case "Y":
			isplay = " 현재 상영 중 ";
			break;
		default:
		}
		isPlaylbl = new JLabel(isplay);
		movieinfopanel.remove(isPlaylbl);
		isPlaylbl.setBackground(new Color(0, 153, 153));
		isPlaylbl.setFont(new Font("맑은 고딕", Font.BOLD, 20));
		isPlaylbl.setHorizontalAlignment(SwingConstants.LEFT);
		movpanel.add(isPlaylbl, BorderLayout.NORTH);
	}

	// 줄거리
	private void movsynop(MovieVO m) {

		ms.searchmovie(m);
		synop = m.getMovsynop();		
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		movieinfopanel.add(panel, BorderLayout.NORTH);
		
		lblNewLabel.setText(m.getMovtitle());
		lblNewLabel.setFont(new Font("맑은 고딕", Font.BOLD, 25));
		lblNewLabel.setBackground(new Color(243, 243, 243));
		panel.add(lblNewLabel);

		panel_1 = new JPanel();
		movieinfopanel.add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(new BorderLayout(0, 0));		
		movieinfopanel.remove(movsynop1);
		movieinfopanel.remove(sPsynop);
		
		
		movsynop1.setText(synop);
		sPsynop.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sPsynop.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
		sPsynop.setPreferredSize(new Dimension(200,200));
		sPsynop.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		panel_1.add(sPsynop);
		sPsynop.setViewportView(movsynop1);
		
		//panel_1.add(movsynop1);
		movsynop1.setBorder(new EmptyBorder(10, 10, 10, 10));
		movsynop1.setBackground(new Color(238, 238, 238));
		movsynop1.setLineWrap(true);
		movsynop1.setPreferredSize(new Dimension(200, 350));

		label_1 = new JLabel("줄거리");
		label_1.setFont(new Font("맑은 고딕", Font.PLAIN, 15));
		panel_1.add(label_1, BorderLayout.NORTH);

	}

	// 지역
	private void moviearea(List<MovieVO> areas) {

		// 영화명을 클릭하기전에는 enable false 로 정의
		// sPmovarea = new JScrollPane(); // 스크롤페인 지역
		sPmovarea.setEnabled(false);
		sPmovarea.setFont(new Font("굴림", Font.PLAIN, 18));
		sPmovarea.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sPmovarea.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		sPmovarea.setPreferredSize(new Dimension(195, 250));
		movresv.add(sPmovarea);

		DefaultTableModel model2 = new DefaultTableModel() {
			@Override
			public boolean isCellEditable(int row, int column) {
				return false;// 열수정 불가 } };
			}
		};
		String title2[] = { "<html><font size='5' face='맑은 고딕'><b>상영중인 지역</b></font></html>" };
		model2.setColumnIdentifiers(title2);

		for (MovieVO a : areas) {
			model2.addRow(new String[] { a.getLocation() });			
		}
		
		movarea = new JTable(model2);
		movarea.validate();
		movarea.repaint();
		movarea.setRowHeight(30);		
		movarea.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {				
				JTable table = (JTable) e.getSource();
				int row = table.getSelectedRow(); // 선택행
				int col = table.getSelectedColumn();// 선택열

				String val = (String) table.getValueAt(row, col);

				m.setLocation(val);

				moviecinema(mselect.clickCinema(m));				
				movarea.validate();
				movarea.repaint();
				caltbl.validate();
				caltbl.repaint();

			}
		});
		sPmovarea.setViewportView(movarea);
		moviecinema(new ArrayList<MovieVO>());
		movarea.setVisible(true);
	}

	// 영화관
	private void moviecinema(List<MovieVO> cine) {
		// 영화명을 클릭하기전에는 enable false 로 정의
		// sPmovarea = new JScrollPane(); // 스크롤페인 지역
		sPmovcinema.setEnabled(false);
		sPmovcinema.setFont(new Font("굴림", Font.PLAIN, 18));
		sPmovcinema.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sPmovcinema.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		sPmovcinema.setPreferredSize(new Dimension(195, 250));
		movresv.add(sPmovcinema);		
		DefaultTableModel model3 = new DefaultTableModel() {
			@Override
			public boolean isCellEditable(int row, int column) {
				return false;// 열수정 불가 } };
			}
		};
		String title3[] = {
				"<html><font size='5' face='맑은 고딕'><b>상영중인</b></font></html>",
				"<html><font size='5' face='맑은 고딕'><b>영화관</b></font></html>"};
		model3.setColumnIdentifiers(title3);		
		for (MovieVO a : cine) {
			model3.addRow(new String[] { a.getCinename(), a.getTheater() });
		}
		
		movcinema = new JTable(model3);
		movcinema.setRowHeight(30);
		movcinema.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				JTable table = (JTable) e.getSource();
				int row = table.getSelectedRow(); // 선택행		

				String cinename = (String) table.getValueAt(row, 0);
				String theater = (String) table.getValueAt(row, 1);

				m.setCinename(cinename);
				m.setTheater(theater);		

				moviecal(mselect.clickDate(m));
				movarea.validate();
				movarea.repaint();
				caltbl.validate();
				caltbl.repaint();
			}
		});
		movcinema.getColumn(title3[0]).setPreferredWidth(120);
		movcinema.getColumnModel().getColumn(1).setCellRenderer(cell);
		sPmovcinema.setViewportView(movcinema);
		moviecal(new ArrayList<MovieVO>());		
		movcinema.setVisible(true);
	}

	// 날짜
	private void moviecal(List<MovieVO> mvo) {
		// caldpanel = new JPanel();
		caldpanel.setPreferredSize(new Dimension(195, 250));
		movresv.add(caldpanel);
		caldpanel.setLayout(new BorderLayout(0, 0));
		
		sPmovdate.setEnabled(false);
		sPmovdate.setFont(new Font("굴림", Font.PLAIN, 18));
		sPmovdate.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sPmovdate.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		sPmovdate.setPreferredSize(new Dimension(185, 32));
		caldpanel.add(sPmovdate, BorderLayout.NORTH);		
		DefaultTableModel datemodel = new DefaultTableModel() {
			@Override
			public boolean isCellEditable(int row, int column) {
				return false;// 열수정 불가 } };
			}
		};
		String datetitle[] = {
				"<html><font size='5' face='맑은 고딕'><b>날짜 선택</b></font></html>"};
		datemodel.setColumnIdentifiers(datetitle);
		JTable movdate = new JTable(datemodel);	
		
		calhdr.setPreferredSize(new Dimension(185, 28));
		caldpanel.add(calhdr, BorderLayout.CENTER);
		calhdr.setLayout(new BorderLayout(0, 0));		
		caldate.setText("2013년 12월");
		caldate.setHorizontalAlignment(SwingConstants.CENTER);
		calhdr.add(caldate, BorderLayout.CENTER);		
		calsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		calsp.setPreferredSize(new Dimension(185, 190));
		caldpanel.add(calsp, BorderLayout.SOUTH);

		caltbl.validate();
		caltbl.repaint();
		caltbl.setRowHeight(25);
		calsp.setViewportView(caltbl);
		caltbl.setCellSelectionEnabled(true);		
		cell = new DefaultTableCellRenderer();
		cell.setHorizontalAlignment(JLabel.CENTER);
		DefaultTableModel model4 = new DefaultTableModel() {
			@Override
			public boolean isCellEditable(int row, int column) {
				return false;// 열수정 불가
			}
		};
		String title4[] = { "일", "월", "화", "수", "목", "금", "토" };
		
		model4.setColumnIdentifiers(title4);
		
		/*TableCellRenderer renderer = new CalTableCellRenderer();
		try {
			caltbl.setDefaultRenderer(Class.forName("java.lang.Object"),renderer);
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		*/
		String[] days = ShowCalendar.getCalendarModel(ca.get(Calendar.YEAR),
				ca.get(Calendar.MONTH) + 1);		

		for (int i = 1; i < days.length; i += 8) {
			if (i + 8 < 42)
				model4.addRow(new String[] { days[i + 0], days[i + 1],
						days[i + 2], days[i + 3], days[i + 4], days[i + 5],
						days[i + 6] });
		}
		
		caltbl.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				JTable table = (JTable) e.getSource();
				int row = table.getSelectedRow(); // 선택행		
				int col = table.getSelectedColumn();

				String day = (String) table.getValueAt(row, col);
				String month = caldate.getText().split("[ ]")[1].substring(0,2);
				String year = caldate.getText().split("[ ]")[0]
						.substring(0, 4);
				//System.out.println(date);
				if (day.length() == 1) {
					m.setSdate(year + month + "0" + day);
				} else if (day.length() == 2) {
					m.setSdate(year + month + day);
				}
				//System.out.println(m.getSdate());

				movieTimePeople(mselect.clickTime(m));
				movarea.validate();
				movarea.repaint();
				caltbl.validate();
				caltbl.repaint();
			}
		});
		

		button_1 = new JButton("▶");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int year = Integer.parseInt(caldate.getText().split("[ ]")[0]
						.substring(0, 4));
				String mon = caldate.getText().split("[ ]")[1];
				int month = Integer.parseInt(mon.substring(0, mon.indexOf("월")));
				
				calhdr.add(caldate, BorderLayout.CENTER);
				if (month + 1 > 12) {
					year = year + 1;
					month = 1;
				} else {
					month += 1;
				}

				caldate.setText(year + "년 " + month + "월");
				String[] days = ShowCalendar.getCalendarModel(year, month);
				DefaultTableModel model4 = new DefaultTableModel() {
					@Override
					public boolean isCellEditable(int row, int column) {
						return false;// 열수정 불가
					}
				};
				String title4[] = { "일", "월", "화", "수", "목", "금", "토" };
				model4.setColumnIdentifiers(title4);
				for (int i = 1; i < days.length; i = i + 8) {
					if (i + 8 < 56)
						model4.addRow(new String[] { days[i + 0], days[i + 1],
								days[i + 2], days[i + 3], days[i + 4],
								days[i + 5], days[i + 6] });
				}				
				caltbl.setModel(model4);

				for (int i = 0; i < caltbl.getColumnCount(); i++) {
					caltbl.getColumnModel().getColumn(i).setCellRenderer(cell);
				}
				caltbl.validate();
				caltbl.repaint();		
				
				calsp.setViewportView(caltbl);
				caltbl.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent e) {
						JTable table = (JTable) e.getSource();
						int row = table.getSelectedRow(); // 선택행		
						int col = table.getSelectedColumn();

						String day = (String) table.getValueAt(row, col);
						String month = caldate.getText().split("[ ]")[1].substring(0,2);
						
						
						String year = caldate.getText().split("[ ]")[0]
								.substring(0, 4);
						//System.out.println(date);
						if (day.length() == 1) {
							m.setSdate(year + month + "0" + day);
						} else if (day.length() == 2) {
							m.setSdate(year + month + day);
						}
						//System.out.println(m.getSdate());
						

						movieTimePeople(mselect.clickTime(m));
						movarea.validate();
						movarea.repaint();
						caltbl.validate();
						caltbl.repaint();
					}
				});

			}
		});
		caltbl.setModel(model4);
		//caltbl.setDefaultRenderer(Object.class, new CalColor());
		/*for (int i = 0; i < caltbl.getColumnCount(); i++) {
			caltbl.getColumnModel().getColumn(i).setCellRenderer(cell);
		}*/
		
		
		
		
		caltbl.validate();
		caltbl.repaint();		
		calhdr.add(button_1, BorderLayout.EAST);

		button = new JButton("◀");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				int year = Integer.parseInt(caldate.getText().split("[ ]")[0]
						.substring(0, 4));
				String mon = caldate.getText().split("[ ]")[1];
				int month = Integer.parseInt(mon.substring(0, mon.indexOf("월")));
				
				if (month - 1 == 0) {
					month = 12;
					year -= 1;
				} else {
					month -= 1;
				}			
				caldate.setText(year + "년 " + (month) + "월");

				String[] days = ShowCalendar.getCalendarModel(year, month);
				DefaultTableModel model4 = new DefaultTableModel() {
					@Override
					public boolean isCellEditable(int row, int column) {
						return false;// 열수정 불가
					}
				};
				String title4[] = { "월", "화", "수", "목", "금", "토", "일" };
				model4.setColumnIdentifiers(title4);
				for (int i = 1; i < days.length; i = i + 8) {
					if (i + 8 < 56)
						model4.addRow(new String[] { days[i + 0], days[i + 1],
								days[i + 2], days[i + 3], days[i + 4],
								days[i + 5], days[i + 6] });
				}
				// caltbl = new JTable();
				caltbl.setModel(model4);
				for (int i = 0; i < caltbl.getColumnCount(); i++) {
					caltbl.getColumnModel().getColumn(i).setCellRenderer(cell);
				}
				caltbl.validate();
				caltbl.repaint();				
				calsp.setViewportView(caltbl);
				
				caltbl.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent e) {
						JTable table = (JTable) e.getSource();
						int row = table.getSelectedRow(); // 선택행		
						int col = table.getSelectedColumn();

						String day = (String) table.getValueAt(row, col);
						String month = caldate.getText().split("[ ]")[1].substring(0,2);
						String year = caldate.getText().split("[ ]")[0]
								.substring(0, 4);
						//System.out.println(date);
						if (day.length() == 1) {
							m.setSdate(year + month + "0" + day);
						} else if (day.length() == 2) {
							m.setSdate(year + month + day);
						}
						//System.out.println(m.getSdate());

						movieTimePeople(mselect.clickTime(m));
						movarea.validate();
						movarea.repaint();
						caltbl.validate();
						caltbl.repaint();
					}
				});
			}
		});
		calhdr.add(button, BorderLayout.WEST);
		
		sPmovdate.setViewportView(movdate);
		//caltbl.setVisible(true);
		movieTimePeople(new ArrayList<MovieVO>());
	}

	/*// 쉘 색 변경
			class CalColor extends DefaultTableCellRenderer {				

			    @Override
			    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
			        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
			        int day = Integer.parseInt(m.getSdate().substring(8, 10));
			        
			        if ((int)table.getValueAt(row, column) == day) {
			        	c.setBackground( new Color(191, 219, 238));
			        } else {
			        	c.setBackground( Color.white );
			        }
			        return c;
			    }
			}
	// 쉘 색 변경
*/			
			
	// 시간, 인원
	private void movieTimePeople(List<MovieVO> peo) {
		peopanel.setPreferredSize(new Dimension(180, 250));
		movresv.add(peopanel);
		peopanel.setLayout(new BorderLayout(0, 0));
		
		sPmovtime.setFont(new Font("굴림", Font.PLAIN, 18));
		sPmovtime.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sPmovtime.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		sPmovtime.setPreferredSize(new Dimension(180, 80));
		peopanel.add(sPmovtime, BorderLayout.NORTH);		
		DefaultTableModel model3 = new DefaultTableModel() {
			@Override
			public boolean isCellEditable(int row, int column) {
				return true;// 열수정 불가 } };
			}
		};
		String timetitle[] = {
				"<html><font size='5' face='맑은 고딕'><b>시간 선택</b></font></html>"};
		model3.setColumnIdentifiers(timetitle);
		
	//String[] ti = {};
		timeCbx = new JComboBox<>();
		timeCbx.addItem("시간을 선택하세요");
		for (MovieVO mv : peo){
			timeCbx.addItem(mv.getStime());
		}
		
			
		model3.addRow(new String[] {"시간을 선택하세요"});
		movtime = new JTable(model3);
		movtime.setRowHeight(30);		
		movtime.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(timeCbx)); 		
		sPmovtime.setViewportView(movtime);		
		
		//sPmovpeople.setEnabled(false);
		sPmovpeople.setFont(new Font("굴림", Font.PLAIN, 18));
		sPmovpeople.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sPmovpeople.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		sPmovpeople.setPreferredSize(new Dimension(180, 80));
		peopanel.add(sPmovpeople, BorderLayout.CENTER);		
		DefaultTableModel model4 = new DefaultTableModel() {
			@Override
			public boolean isCellEditable(int row, int column) {
				return true;// 열수정 불가 } };
			}
		};
	
		String title3[] = {
				"<html><font size='5' face='맑은 고딕'><b>구분</b></font></html>",
				"<html><font size='5' face='맑은 고딕'><b>인원 선택</b></font></html>"};
		model4.setColumnIdentifiers(title3);
		String[] ra = {};
		if (m.getMovrating() == null) {
			ra = new String[] {};
		} else if (m.getMovrating().equals("청소년 관람불가")) {
			ra = new String[] {"등급선택", "일반"};
		} else {
			ra = new String[] {"등급선택", "일반", "청소년"};
		}			
		
		
		String[] po = {"인원선택", "1명", "2명", "3명", "4명", "5명", "6명", "7명", "8명"};
		peopleCbx = new JComboBox<>(po);		
		rateCbx = new JComboBox<>(ra);		
		model4.addRow(new String[] {"구분선택", "인원을 선택하세요"});
		movpeople = new JTable(model4);
		movpeople.setRowHeight(30);		
		
		movpeople.getColumnModel().getColumn(0).setPreferredWidth(30);
		movpeople.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(peopleCbx));		
		movpeople.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(rateCbx));		
		sPmovpeople.setViewportView(movpeople);		
		movpeople.setVisible(true);		
		
		JButton okBtn = new JButton("좌 석 선 택");
		okBtn.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		okBtn.addActionListener(bal);
		okBtn.setActionCommand("ok");
		peopanel.add(okBtn, BorderLayout.SOUTH);
		okBtn.setPreferredSize(new Dimension(180,90));
	}
	
	private class BtnActionListener implements ActionListener {
		private UserVO u = null;
		public BtnActionListener(UserVO u) {
			this.u = u;
		}
		@Override
		public void actionPerformed(ActionEvent e) {
			switch(e.getActionCommand()) {
			case "ok":
				m.setStime((String)timeCbx.getSelectedItem());
				m.setUserrate((String)rateCbx.getSelectedItem());
				m.setPeoplenum((String)peopleCbx.getSelectedItem());				
				
				if (m.getMovtitle() == null) {
					JOptionPane.showMessageDialog(null, "영화를 선택하세요.", "", JOptionPane.WARNING_MESSAGE);
				} else if (m.getLocation() == null || m.getCinename() == null || m.getTheater()==null) {
					JOptionPane.showMessageDialog(null, "영화관을 선택하세요.", "",  JOptionPane.WARNING_MESSAGE);
				} else if (m.getSdate() == null || timeCbx.getSelectedIndex() == 0) {
					JOptionPane.showMessageDialog(null, "날짜, 시간을 선택하세요.", "", JOptionPane.WARNING_MESSAGE);
				} else if (rateCbx.getSelectedIndex() == 0 || peopleCbx.getSelectedIndex() == 0) {
					JOptionPane.showMessageDialog(null, "인원을 선택하세요.", "", JOptionPane.WARNING_MESSAGE);
				} else {
					new S_MovieSeatDialog(m, u);
				}
				break;
			}
			
		}
	}
	
	/*public class CalTableCellRenderer extends DefaultTableCellRenderer {
		@Override
		public Component getTableCellRendererComponent(JTable table,
				Object value, boolean isSelected, boolean hasFocus, int row,
				int col) {
			Component cell = super.getTableCellRendererComponent(table, value,
					isSelected, hasFocus, row, col);
			
			//String d = ms.clickCal(m);

			if ("1".equals(table.getValueAt(row, col))) {
				cell.setBackground(Color.orange);
				System.out.println(row + "/ " + col);
			} else {
				cell.setBackground(Color.blue);
			}

			return cell;
		}
	}*/

}
